package interceptor;

import java.util.Map;

import org.apache.struts2.ServletActionContext;


import beans.Agent;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

@SuppressWarnings("serial")
public class LoginedCheckInterceptor extends AbstractInterceptor {
	
	
	/**
	 *Session 认证
	 */
	public String intercept(ActionInvocation ai) throws Exception {
		
		if(!ServletActionContext.getRequest().isRequestedSessionIdValid()||
				ServletActionContext.getRequest()==null){
			return "login";
		}
		
		ActionContext ctx = ai.getInvocationContext();
		Map<String, Object> session = ctx.getSession();
		Agent admin = (Agent)session.get("admin");
		if (admin != null )
		{
			return ai.invoke();
		}else{
			return "login";
		}
	}

}
